package org.fioma.tree;

import org.fioma.tree.bytes.Tools;

public abstract class SimpleInternalNode<L, I extends SimpleInternalNode<L, I, F>, F extends SimpleLeaf<L, I, F>> extends SimpleNode<L, I, F> implements
		InternalNode<L, I, F> {

	protected Node<L, I, F>[] nodes;

	public SimpleInternalNode() {
		nodes = new Node[4];
	}

	@Override
	public Node<L, I, F> nextNode(char letter) {
		return nextNode(Tools.transformToByte(letter));
	}

	@Override
	public Node<L, I, F> nextNode(byte letter) {
		return nodes[letter];
	}

	@Override
	public void setChild(Node<L, I, F> node, char letter) {
		setChild(node, Tools.transformToByte(letter));
	}

	@Override
	public void setChild(Node<L, I, F> node, byte letter) {
		nodes[letter] = node;
	}

	@Override
	public boolean isLeaf() {
		for (Node<L, I, F> node : nodes) {
			if (node != null) {
				return true;
			}
		}
		return false;
	}

}
